import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
  server: {
    proxy: {
      '/api': {
        target: 'http://124.223.177.21:8088', //请求的接口
        changeOrigin: true, //允许跨域
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },

  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],

  base: './', // 更改 base 为当前目录
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    outDir: 'dist', // 修改为 outDir 来指定输出目录
    assetsDir: 'assets', // 设置输出文件的目录
    cssCodeSplit: true // 开启 CSS 代码拆分
  }
})
